#ifndef __SERVER_CONNECTOR_H__
#define __SERVER_CONNECTOR_H__
#include <vector>
#include <utility>
#include <set>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netdb.h>
#include <ncurses.h>
#include <map>
#include "Connector.h"
#include "../Settings/Settings.h"
#include "StringParser.h"
#include "CommandMaker.h"

class ServerConnector: public Connector
{
private:
  struct sockaddr_in serv_addr;
  //std::vector <std::pair<struct sockaddr_in, socklen_t> > cli_addrs;
  int portNum;
  Settings &settings_;
  StringParser parser;
  CommandMaker cmaker;

  static const int BUFFER_LENGTH;
    
  int listener;
  int lastConnected;
  char buffer[1024];
  std::set<int> clients;
  std::map<int, bool> registeredClients;
  fd_set readset;  
  bool opened;

  int sendMessageToClient(const int client, const std::string &message);
public:
  

  ServerConnector();
  ~ServerConnector();
  int open();
  //some of players opens card
  int openCard(int playerNum);

  //some of players gets totem
  int getTotem(int playerNum);
   

  int connect(const std::string &name, const time_t &connectTime, int &error);
  bool addClient(int newClient);
  int getMessage();
  int acceptClients();
  
  char getMove(bool &toExit);
  
  void quit(int num);
  
  void close();
  void disconnect();
};


#endif
